<?php

/*
  | --------------------------------------------------------------------------------------------------
  | <login_view>
  |
  | Desenvolvedor:	Eduardo Sirangelo
  | E-mail:		sirangelos@ibest.com.br
  | Descrição:
  |	-
  | Quality is Everyting
  | --------------------------------------------------------------------------------------------------
 */
?>
<!doctype html>
<!--[if lt IE 8 ]><html lang="en" class="no-js ie ie7"><![endif]-->
<!--[if IE 8 ]><html lang="en" class="no-js ie"><![endif]-->
<!--[if (gt IE 8)|!(IE)]><!--><html lang="en" class="no-js"><!--<![endif]-->
<head>
	<meta charset="UTF-8">
        <meta name="robots" content="noindex, nofollow" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	
	<title><?=$titulo?></title>
	
	<!-- Global stylesheets -->
	<link href="<?=base_url()?>public/css/reset.css" rel="stylesheet" type="text/css"/>
	<link href="<?=base_url()?>public/css/common.css" rel="stylesheet" type="text/css"/>
	<link href="<?=base_url()?>public/css/form.css" rel="stylesheet" type="text/css"/>
	<link href="<?=base_url()?>public/css/standard.css" rel="stylesheet" type="text/css"/>
	<link href="<?=base_url()?>public/css/special-pages.css" rel="stylesheet" type="text/css"/>
	
	<!-- Favicon -->
	<link rel="shortcut icon" type="image/x-icon" href="<?=base_url()?>public/images/favicon.ico"/>
	<link rel="icon" type="image/png" href="<?=base_url()?>public/images/favicon-large.png"/>
	
	<!-- Modernizr for support detection, all javascript libs are moved right above </body> for better performance -->
	<script src="<?=base_url()?>public/js/libs/modernizr.custom.min.js"></script>
	
</head>

<!-- the 'special-page' class is only an identifier for scripts -->
<body class="special-page login-bg dark">

	<section id="login-block">
		<div class="block-border"><div class="block-content">
			
			<!--
			IE7 compatibility: if you want to remove the <h1>, 
			add style="zoom:1" to the above .block-content div
			-->
			<h1>Hair 1.0</h1>
			<div class="block-header">Sistema de Login</div>
			
			<!--<p class="message error no-margin">Error message</p>-->
			
			<form class="form with-margin" name="login-form" id="login-form" method="post" action="/login/logar/">
				<input type="hidden" name="a" id="a" value="send">
				<p class="inline-small-label">
					<label for="login"><span class="big">E-mail</span></label>
					<input type="text" name="email" id="email" class="full-width" value=""/>
				</p>
				<p class="inline-small-label">
					<label for="pass"><span class="big">Senha</span></label>
					<input type="password" name="pass" id="pass" class="full-width" value=""/>
				</p>
				
				<button type="submit" class="float-right">Login</button>
				<p class="input-height">
					<input type="checkbox" name="keep-logged" id="keep-logged" value="1" class="mini-switch" checked="checked"/>
					<label for="keep-logged" class="inline">Mantenha-me logado</label>
				</p>
			</form>
			
			<form class="form" id="password-recovery" method="post" action="/login/save_new_request/">
				<fieldset class="grey-bg no-margin collapse">
					<legend><a href="#">Não possui uma conta?</a></legend>
					<p class="input-with-button">
						<label for="recovery-mail">Informe seu e-mail e receba informações sobre este produto</label>
						<input type="text" name="recovery-mail" id="recovery-mail" value="">
						<button type="button">Enviar</button>
					</p>
				</fieldset>
			</form>
		</div></div>
	</section>
	
	<!--
	
	Updated as v1.5:
	Libs are moved here to improve performance
	
	-->
	
	<!-- Generic libs -->
	<script src="<?=base_url()?>public/js/libs/jquery-1.6.3.min.js"></script>
	<script src="<?=base_url()?>public/js/old-browsers.js"></script>		<!-- remove if you do not need older browsers detection -->
	
	<!-- Template libs -->
	<script src="<?=base_url()?>public/js/common.js"></script>
	
	<!--[if lte IE 8]><script src="<?=base_url()?>public/js/standard.ie.js"></script><![endif]-->
	<script src="<?=base_url()?>public/js/jquery.tip.js"></script>
	
	<!-- example login script -->
	<script>
	
		$(document).ready(function()
		{
			// We'll catch form submission to do it in AJAX, but this works also with JS disabled
			$('#login-form').submit(function(event)
			{
				// Stop full page load
				event.preventDefault();
				
				// Check fields
				var login = $('#email').val();
				var pass = $('#pass').val();
				
				if (!login || login.length == 0)
				{
					$('#login-block').removeBlockMessages().blockMessage('Por favor informe seu e-mail', {type: 'warning'});
				}
				else if (!pass || pass.length == 0)
				{
					$('#login-block').removeBlockMessages().blockMessage('Por favor informe sua senha', {type: 'warning'});
				}
				else
				{
					var submitBt = $(this).find('button[type=submit]');
					submitBt.disableBt();
					
					// Target url
					var target = $(this).attr('action');
					if (!target || target == '')
					{
						// Page url without hash
						target = document.location.href.match(/^([^#]+)/)[1];
					}
					
					// Request
					var data = {
							a: $('#a').val(),
							login: login,
							pass: pass,
							'keep-logged': $('#keep-logged').attr('checked') ? 1 : 0
						},
						redirect = $('#redirect'),
						sendTimer = new Date().getTime();
					
					if (redirect.length > 0)
					{
						data.redirect = redirect.val();
					}
					
					// Send
					$.ajax({
						url: target,
						dataType: 'json',
						type: 'POST',
						data: data,
						success: function(data, textStatus, XMLHttpRequest)
						{
							if (data.valid)
							{
								// Small timer to allow the 'cheking login' message to show when server is too fast
								var receiveTimer = new Date().getTime();
								if (receiveTimer-sendTimer < 500)
								{
									setTimeout(function()
									{
										document.location.href = data.redirect;
										
									}, 500-(receiveTimer-sendTimer));
								}
								else
								{
									document.location.href = data.redirect;
								}
							}
							else
							{
								// Message
								$('#login-block').removeBlockMessages().blockMessage(data.error || 'Ops! Ocorreu um erro inesperado. Por favor, tente novamente', {type: 'error'});
								
								submitBt.enableBt();
							}
						},
						error: function(XMLHttpRequest, textStatus, errorThrown)
						{
							// Message
							$('#login-block').removeBlockMessages().blockMessage('Erro ao tentar acessar o servidor. Por favor, tente novamente', {type: 'error'});
							
							submitBt.enableBt();
						}
					});
					
					// Message
					$('#login-block').removeBlockMessages().blockMessage('Aguarde, verificando login...', {type: 'loading'});
				}
			});
		});
	
	</script>

</body>

</html>
